PaymentsInfoPanel = function(limit){
	/**
	 * 打开表单
	 **/
	var openQueryUserWindow = function(){
		var win = new UserInfoWindow({title:'查找用户'});
		win.show();
		win.on('submit',function(userwin,infogrid,data){
			queryuserpanel.getForm().findField('username').setValue(data.username);
			queryuserpanel.getForm().findField('telephone').setValue(data.telephone);
			queryUsers();
		});
	};
	
	/**
	 * 查询人员信息 
	 **/
	var queryUsers = function(){
		var url = __ctxPath+'/back/userunit/finduserunitinfoisowed.html';
		var objs = queryuserpanel.getForm().getValues();
		if(objs.username ==''&&objs.telephone==''){
			msg('系统提示','请填写人员信息进行查询!',Ext.MessageBox.WARNING);
			return;
		};
		if(objs.username ==''){delete objs.username};
		if(objs.telephone==''){delete objs.telephone};
		var _obj = Ext.applyIf({start:0,limit:20},objs);
		var _store=store;
		_store.proxy.setUrl(url,true);
		_store.baseParams = _obj;
		_store.load({params:_obj});
	}
	var resetQuery = function(){
		queryuserpanel.getForm().reset();
	}
	var queryuserpanel = new Ext.FormPanel(
		{
			flex:1,
			frame:true,
			height:100,
			border:false,
			title:'查找用户',
            layout: {
	            type: 'hbox',
	            align:'stretch',
//	            padding:5,
	            pack:'start'
	        },
	        defaults: {
	            layout:'form',
	            labelWidth:30,
	            border:false
	        },
	        items: [
	        	{
	        	  height:100,
	        	  flex:1,
	        	  items:[
	        	  	{
	        	  	  xtype:'textfield',
		        	  fieldLabel:'姓名',
		        	  name:'username',
		        	  anchor:'90%',
		        	  value:''
	        	  	}
	        	  ]
	        	},{
	        	  height:100,
	        	  flex:1,
	        	  items:[
	        	  	{
			            layout:'form',
			            labelWidth:60,
			            items:[{
		        	  	  xtype:'textfield',
			        	  fieldLabel:'电话号码',
			        	  name:'telephone',
			        	  anchor:'90%',
			        	  value:''
		        	  	}],
			            border:false
			        }
	        	  	
	        	  ]
	        	},{
	        	  height:100,
	        	  flex:1,
	        	  items:[
	        	  	{
	        	  	  xtype:'button',
	        	  	  iconCls:'page_find',
		        	  text:'查询',
		        	  anchor:'10%',
					handler:queryUsers
	        	  	}
	        	  ]
	        	}
	        ],
			buttons:[
				{
					text:'精确查找',
					iconCls:'zoom',
					handler:openQueryUserWindow,
					scope:this
				},{
					text:'重置',
					iconCls:'table_refresh',
					handler:resetQuery
				}
			]
		}
	);
	
	var store = new Ext.data.JsonStore(
		{
			url:__ctxPath+'/back/userunit/finduserunitinfoisowed.html',
			fields:['uid','areaname','address','areaid',
			'username','areaforbuild','areaforfees',
			'regdate','telephone','notes','payyear']
		}
	);
	var paymentFeeInfo = function(grid, rowIndex, colIndex) {
		var rec = store.getAt(rowIndex);
       	var win = new PaymentsWindow('开始缴费');
       	win.show();
       	win.setIconClass('money_yen');
       	rec.set('userid',rec.get('uid'));
       	rec.set('name',rec.get('username'));
       	win.load(rec);
       	win.on('submit',function(win,form,data){
			form.getForm().submit(
				{
					url:__ctxPath+'/back/fees/addpayments.html',
					clientValidation:true,
					waitTitle:'系统提示',
					waitMsg:'系统正在处理提交的数据信息,...', 
					method:'POST',
					success:function(form,action){
						if(action.result.success){
							SX.Util.msg('系统提示', '缴费成功');
							msg('系统提示','缴费成功!',Ext.MessageBox.WARNING);
							
							win.close();
							loadHistory(rec.get('uid'));
							/*var rec = new Ext.data.Record(data);
							rec.set('fid',action.result.id);
							rec.commit();
							store.insert(0,rec);
							Ext.MessageBox.alert('系统提示','添加成功!');
							win.close();
							me.getView().refresh();*/
						}else{
							/*Ext.MessageBox.alert('系统提示','添加失败!');*/
						}	
					},
					failure:function(form,action){
						/*Ext.MessageBox.alert('系统提示','网络原因 添加失败');*/
					}
				}
			);
		});
    };
	var updateUserInfo = function(grid, rowIndex, colIndex) {
        var rec = store.getAt(rowIndex);
        var win = new UserUnitWindow('修改用户信息');
		win.setIconClass('user_edit');
		win.show();
		win.load(rec);
		
		var comboarea = win.items.items[0].getForm().findField('areaid');
		comboarea.setValue(rec.get('areaid'));
		comboarea.setRawValue(rec.get('areaname'));
		win.on('submit',function(win,form,data){
			form.getForm().submit(
				{
					url:__ctxPath+'/back/userunit/edituserunit.html',
					method:'POST',
					success:function(form,action){
						if(action.result.success){
							var d = rec.data;
							for(var i in d){
								rec.set(i,data[i]);
							}
							rec.commit();
							win.close();
							Ext.MessageBox.alert('系统提示','修改成功!');
						
						}else{
							Ext.MessageBox.alert('系统提示','修改失败!');
						}	
					},
					failure:function(form,action){
						Ext.MessageBox.alert('系统提示','网络原因 修改失败');
					}
				}
			);
		});
    }
	var userinfocm = [
		new Ext.grid.RowNumberer(),
		{
            xtype: 'actioncolumn',
            header:'操作',
            width: 50,
            items: [
            {
                iconCls :'money_yen',
                icon:'/sx/assert/ext/ui/icon/money_yen.png',
                tooltip: '开始缴费',
                handler: paymentFeeInfo
            }, {
                iconCls :'',
                icon:'/sx/assert/ext/ui/icon/user_edit.gif',
                tooltip: '修改用户信息',
                handler: updateUserInfo
            }]
        },
		{header:'用户名称',dataIndex:'username',sortable: true,width:100},
		{header:'小区名称',dataIndex:'areaname',sortable: true,width:100},
		{header:'住址',dataIndex:'address',sortable: true,width:200},
		{header:'建筑面积',dataIndex:'areaforbuild',sortable: true,width:100},
		{header:'采暖面积',dataIndex:'areaforfees',sortable: true,width:100},
		{header:'联系电话',dataIndex:'telephone',sortable: true,width:100},
		{header:'缴费年度',dataIndex:'payyear',sortable: true,width:200,
			renderer:function(value,meta,rec){
				var str = '';
				if(value==''){
					str = '<span style="color:red;">已欠费</span>';
				}else{
					str = '<span style="color:green;">'+value+'已缴费</span>';
				}
				return str;
			}
		},
		{header:'备注',dataIndex:'notes',sortable: true,width:200}
	];
	
	var loadHistory = function(userid){
		var url =__ctxPath+'/back/fees/findpayments.html';
		var objs = {userid:userid};
		var _obj = Ext.applyIf({start:0,limit:20},objs);
		var _store=historystore;
		_store.proxy.setUrl(url,true);
		_store.baseParams = _obj;
		_store.load({params:_obj});
	};
	
	var rowselect = function(sel,index,r){
		loadHistory(r.get('uid'));
		//给用户模版赋值数据信息
		var data = r.data;
		tpl.overwrite(userdetailpanel.body, data);
        userdetailpanel.body.highlight('#c3daf9', {block:true});
	};
	var queryuserresultgrid = new Ext.grid.GridPanel(
		{
			layout:'fit',
			border:false,
			height:100,
			store:store,
			selModel:new Ext.grid.RowSelectionModel({listeners:{'rowselect':{fn:rowselect,scope:this}}}),
			columns:userinfocm
		}
	);
	
	//Template 用户模版
	var tpl = new Ext.XTemplate(
        '<p>用户名称: {username}</p>',
        '<p>电话: {telephone}</p>',
        '<p>小区名称: {areaname}</p>',
        '<p>住址: {address}</p>',
        '<p>备注: {notes}</p>'
        
    );
	
	//用户信息界面
	var userdetailpanel = new Ext.Panel(
		{
			title:"用户信息",
	    	html:'', 
	    	flex:1
		}
	);
	var historysm = new Ext.grid.CheckboxSelectionModel();
	var historycm = [
		new Ext.grid.RowNumberer(),
		{header:'缴费时间',dataIndex:'paydate',sortable: true,width:150},
		{header:'缴费金额',dataIndex:'realpay',sortable: true,width:100},
		{header:'应收金额',dataIndex:'shouldpay',sortable: true,width:100},
		{header:'折扣金额',dataIndex:'discount',sortable: true,width:100},
		{header:'减免金额',dataIndex:'minuspay',sortable: true,width:100},
		{header:'票号',dataIndex:'receiptno',sortable: true,width:100},
		{header:'联系电话',dataIndex:'telephone',sortable: true,width:100},
		{header:'缴费年度',dataIndex:'payyear',sortable: true,width:100},
		{header:'备注',dataIndex:'notes',sortable: true,width:100}
	];
	var historystore = new Ext.data.JsonStore(
		{
			totalProperty:'totalCount',
			root:'data',
			url:__ctxPath+'/back/fees/findpayments.html',
			fields:['paydate','realpay','shouldpay','discount','minuspay',
			'telephone','payyear','notes','receiptno']
		}
	);
	var historygrid = new Ext.grid.GridPanel(
		{
			layout:'fit',
			height:100,
			store:historystore,
			/*sm:historysm,*/
			columns:historycm
		}
	);
	
	var centerpanel = new Ext.Panel(
		{
			layout:'vbox',
			border:false,
			layoutConfig: {
			    align : 'stretch',
			    pack  : 'start'
			},
			items: [
			    {
			    	layout:'fit',
			    	height:100,
			    	items:[queryuserpanel]
			    },{
			    	layout:'fit',
			    	border:false,
			    	items:[queryuserresultgrid],
			    	height:100
			    },{ 
			    	flex:2,
			    	layout:'hbox',
			    	border:false,
					layoutConfig: {
					    align : 'stretch',
					    pack  : 'start'
					},
					items: [
					    userdetailpanel,
					    {
					    	title:'缴费记录',
					    	items:[historygrid],
					    	layout:'fit',
					    	flex:3
					    }
					]
			    }
			]		
		}
	);
	
	var config = {
		layout:'fit',
		items:[centerpanel],
		height:500,
		title:'用户缴费',
		iconCls:'zoom',
		id:'PaymentsInfoPanel'
	};
	PaymentsInfoPanel.superclass.constructor.call(this,config);
};
Ext.extend(PaymentsInfoPanel,Ext.Panel);